/******************************************************************************
**                 Proprietary and Confidential Information                  **
**                                                                           **
**                Copyright (c) 2010 Conexant Systems, Inc.                  **
**                                                                           **
**  This software contains proprietary and confidential material which is    **
**  the property of Conexant Systems, Inc.                                   **
**                                                                           **
******************************************************************************/
#ifndef _dc_jim_api_h_
#define _dc_jim_api_h_
/******************************************************************************
*  FILE FORMAT: <PUBLIC>
*      1. INCLUDES 
*      2. ENUMERATIONS 
*      3. DEFINES
*      4. STRUCTURES
*      5. GLOBALS
*      6. PUBLIC FUNCTION PROTOTYPES
******************************************************************************/
/******************************************************************************
*  1. INCLUDES
******************************************************************************/

#include "dc_jpeg_api.h"
#include "jpeg_parser_api.h"

/******************************************************************************
*  2. ENUMERATIONS
******************************************************************************/

typedef enum DC_JIM_JOB_PRIORITY
{
    DC_JIM_JOB_PRIORITY_DEFAULT = 0,
    DC_JIM_JOB_PRIORITY_HIGH,
} DC_JIM_JOB_PRIORITY;

typedef enum DC_JIM_JOB_TYPE
{
    DC_JIM_JOB_TYPE_GET_RGB_FROM_MEDIA_STORE = 0,
    DC_JIM_JOB_TYPE_GET_RGB_FROM_DC_DMBIMG,					// currently unsupported
} DC_JIM_JOB_TYPE;

typedef enum DC_JIM_STATUS
{
    DC_JIM_SUCCESS = 0,
    DC_JIM_SUCCESS_CANCEL,
    DC_JIM_ERROR_FILE_OPEN,
    DC_JIM_ERROR_FILE_SEEK,
    DC_JIM_ERROR_FILE_GETPOS,
    DC_JIM_ERROR_FILE_READ,
    DC_JIM_ERROR_FILE_PARSE,
    DC_JIM_ERROR_INVALID_FILE_TYPE,
	DC_JIM_ERROR_INVALID_SOURCE_IMAGE,
    DC_JIM_ERROR_NO_THUMB_IN_FILE,
    DC_JIM_ERROR_RGB_FORMAT,
    DC_JIM_ERROR_ROTATION,
    DC_JIM_ERROR_FRAME_SHORT_STRIDE,
	DC_JIM_ERROR_STREAM_FILE_THREAD,
    DC_JIM_ERROR_IMGBUF_STALL_TIMEOUT,
    DC_JIM_ERROR_UNKNOWN_JOB_TYPE,
    DC_JIM_ERROR_UNKNOWN_JOB_STATE,
    DC_JIM_ERROR_JPEGPIPE_SETUP,
    DC_JIM_ERROR_JPEGPIPE_CREATE,
    DC_JIM_ERROR_JPEGPIPE_PROCESS,
    DC_JIM_ERROR_INVALID_COLORSPACE,
    DC_JIM_ERROR_ACQUIRE_JH_RESOURCES,
    DC_JIM_STATUS_JOB_IN_HP_QUEUE,
    DC_JIM_STATUS_JOB_IN_DP_QUEUE,
    DC_JIM_STATUS_JOB_ACTIVE,
    DC_JIM_STATUS_JOB_UNKNOWN,
	DC_JIM_STATUS_HP_PREEMPTION,
} DC_JIM_STATUS;

typedef enum DC_JIM_RGB_FORMAT
{
    DC_JIM_RGB_565 = 2,         // 16 bpp: 5 bits for red (MSB), 6 bits for green, 5 bits for blue (LSB)
    DC_JIM_RGB_888 = 3,         // 24 bpp: 8 bits for red (MSB), 8 bits for green, 8 bits for blue (LSB)
    DC_JIM_RGB_8888 = 4,        // 32 bpp: 8 bits set to zero (MSB), 8 bits for red,
								//         8 bits for green, 8 bits for blue (LSB)
} DC_JIM_RGB_FORMAT;

typedef enum DC_JIM_SOURCE_IMAGE
{
    DC_JIM_ORIGINAL_IMAGE = 0,          // Image source must be original image
    DC_JIM_THUMBNAIL_IMAGE,             // Image source must be thumbnail image
    DC_JIM_THUMBNAIL_IMAGE_PREFERRED,   // Use thumbnail image if it exists, otherwise use original image
} DC_JIM_SOURCE_IMAGE;

typedef enum DC_JIM_ROTATION
{
    DC_JIM_ROTATION_0 = 0,
    DC_JIM_ROTATION_90,
    DC_JIM_ROTATION_180,
    DC_JIM_ROTATION_270,
} DC_JIM_ROTATION;

/******************************************************************************
*  3. DEFINES
******************************************************************************/

typedef UINT32 DC_JIM_JOB_ID;

/******************************************************************************
*  4. STRUCTURES
******************************************************************************/

typedef struct DC_JIM_ELAPSED_TIMES
{
    UINT32 total;
    UINT32 fileParse;
    UINT32 fileRead;
    UINT32 imageRender;
} DC_JIM_ELAPSED_TIMES;

typedef struct DC_JIM_FRAME_DESC
{
    UINT32 baseAddress;
    UINT32 stride;				// in bytes
    UINT32 width;				// in pixels
    UINT32 height;				// in lines
} DC_JIM_FRAME_DESC;

typedef struct DC_JIM_IMAGE_METADATA
{
	struct
	{
		unsigned int imageSOFType:1;
		unsigned int imageWidth:1;
		unsigned int imageHeight:1;
		unsigned int imageComponentCount:1;
		unsigned int exifThumbnailExists:1;
		unsigned int thumbnailSOFType:1;
		unsigned int thumbnailWidth:1;
		unsigned int thumbnailHeight:1;
		unsigned int thumbnailComponentCount:1;
		unsigned int thumbnailOffset:1;
		unsigned int thumbnailLength:1;
	} is_valid;
    SOF_TYPE imageSOFType;
	UINT32 imageWidth;
	UINT32 imageHeight;
	int imageComponentCount;
	boolean exifThumbnailExists;
    SOF_TYPE thumbnailSOFType;
	UINT32 thumbnailWidth;
	UINT32 thumbnailHeight;
	int thumbnailComponentCount;
	UINT32 thumbnailOffset;
	UINT32 thumbnailLength;
} DC_JIM_IMAGE_METADATA;

typedef struct DC_JIM_CROP_BOX
{
    // Crop box descriptor, used for input image (for zooming)
    // and output display (for aspect ratio preservation borders)

    // Enable or disable crop box
    boolean enabled;
    
    // Corner points are pixel offsets
    // and are inclusive to crop box
    // That is, crop box width is (lowerRightX - upperLeftX + 1)
    // and crop box height is (lowerRightY - upperLeftY + 1)
    UINT16 upperLeftX;
    UINT16 upperLeftY;
    UINT16 lowerRightX;
    UINT16 lowerRightY;
} DC_JIM_CROP_BOX;

typedef struct DC_JIM_STATUS_DESC
{
    DC_JIM_STATUS status;

    // Status from JPEGPIPE if above status is JIM_ERROR_JPEGPIPE_PROCESS
    DC_JPEGPIPE_ERROR_t jpegpipeStatus;

    // Actual source image used (original or thumbnail)
    // For DC_JIM_JOB_TYPE_GET_RGB_FROM_MEDIA_STORE only
    DC_JIM_SOURCE_IMAGE imageUsed;    

    DC_JIM_ELAPSED_TIMES elapsedTimes;
} DC_JIM_STATUS_DESC;

typedef struct DC_JIM_JOB_DESC
{
    DC_JIM_JOB_TYPE jobType;

	// If enableInterleavedReadAndRender is FALSE, then dc_jim
	// will wait until entire image stream is read into memory before
	// passing the image stream to JPEGPIPE.  If TRUE, then JPEGPIPE
	// will be started as soon as the input stream read is started.
    boolean enableInterleavedReadAndRender;
    
    // Pointer to complete pathname of input image file
    // For DC_JIM_JOB_TYPE_GET_RGB_FROM_MEDIA_STORE only
    char *fileName;
   
   	// This structure is used to pass in image file metadata
	// that was previously obtained by the client during a
	// metadata parse of the image file.  Providing the
	// metadata information is optional (see the is_valid
	// member for describing valid data).  However,
	// if metadata need by dc_jim is missing, the dc_jim
	// will have to parse the file and incur the subsequent
	// performance penalty.
	DC_JIM_IMAGE_METADATA imageMetadata;

    // Output RGB Format
    DC_JIM_RGB_FORMAT rgbFormat;

    // Get JPEG source from thumbnail or original image
    DC_JIM_SOURCE_IMAGE sourceImage;

    // Input Crop Box
    // Defines a sub-region of source image, used to effect zooming and panning.
    // This crop box is relative to the source image native
    // orientation, not the desired output orientation (rotation).
    // If icb.enabled is FALSE, use entire source image.
    DC_JIM_CROP_BOX icb;

    // The output frame buffer into which the JPEG image will be rendered
    DC_JIM_FRAME_DESC outputFrame;
    
    // Output Crop Box
    // Used to effect background fill when image aspect ratio
    // does not equal output frame aspect ratio.  This crop
    // box is relative to the outputFrame;
    // that is, it describes the placement of the rendered, and
    // possibly rotated, image within the display frame.
    // If ocb.enabled is FALSE, render into entire outputFrame.
    DC_JIM_CROP_BOX ocb;
    
    // Background Fill Pixel
    // Used in outputFrame regions not covered by output crop box.
    // Pack pixel channels in RGB order toward LSB:
    // DC_JIM_RGB_565:
    //   fillPixel[15:11] is red
    //   fillPixel[10:5] is green
    //   fillPixel[4:0] is blue
    // DC_JIM_RGB_888:
    //   fillPixel[23:16] is red
    //   fillPixel[15:8] is green
    //   fillPixel[7:0] is blue
    // DC_JIM_RGB_8888:
    //   fillPixel[31:24] is overlay index or null
    //   fillPixel[23:16] is red
    //   fillPixel[15:8] is green
    //   fillPixel[7:0] is blue
    UINT32 fillPixel;

    // Output Rotation
    DC_JIM_ROTATION rotation;

    // Output Color Inversion
    // TRUE means Native Image Format (white is 0/0/0, black is 255/255/255)
    // FALSE means Native Image Format inverted (white is 255/255/255, black is 0/0/0)
    // (Use FALSE for RGB display images)
    UINT8 invertEnabled;

    // Color Table 
    // Set cscMode to DC_JPEGPIPE_CSC_MODE_DEFAULT for default built-in tables
    // Set cscMode to DC_JPEGPIPE_CSC_MODE_NONE for native YCBCr output
    // Set cscMode to DC_JPEGPIPE_CSC_MODE_CUSTOM for a user-supplied table
    // If DC_JPEGPIPE_CSC_MODE_CUSTOM, set colorTable to custom 9x9x9x4 color table, compressed using dc_ctzip.exe
	DC_JPEGPIPE_CSC_MODE_t cscMode;
    UINT8 *colorTable;

    // Tonal Response Curves
    // 65 bytes: [0,...,64] map to [0,...,255], HW performs linear interpolation
    // If trcEnabled is TRUE, then trcTable[3] must have pointers to TRC tables
    // If trcEnabled is FALSE, then trcTable[3] should be NULL
    boolean trcEnabled;
    UINT8 *trcTable[3];
} DC_JIM_JOB_DESC;

/******************************************************************************
*  5. GLOBALS
******************************************************************************/

/******************************************************************************
*  6. PUBLIC FUNCTION PROTOTYPES
******************************************************************************/

DC_RETURN_CODE dc_jim_setup(DC_MEM_PARAMS_t *pMemParams);

DC_RETURN_CODE dc_jim_create(DC_MEM_PARAMS_t *pMemParams);

DC_RETURN_CODE dc_jim_delete(void);

DC_RETURN_CODE dc_jim_submit_job(DC_JIM_JOB_DESC *pJobDesc,
                                DC_JIM_JOB_ID *pJobID,
								DC_JIM_JOB_PRIORITY priority,
                                void (*jobCallback)(void *clientArg,DC_JIM_STATUS_DESC *pStatusDesc),
                                void *clientArg);

DC_RETURN_CODE dc_jim_cancel_job(DC_JIM_JOB_ID jobID);

DC_RETURN_CODE dc_jim_cancel_all_jobs(void);

DC_RETURN_CODE dc_jim_get_job_status(DC_JIM_JOB_ID jobID,DC_JIM_STATUS *pStatus);

DC_RETURN_CODE dc_jim_change_job_priority(DC_JIM_JOB_ID jobID,DC_JIM_JOB_PRIORITY priority,DC_JIM_STATUS *pStatus);


#endif

